package com.next

class MessageTemplate
{
    String name
    String text

    String template

    User createBy
    User modifyBy

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    static constraints = {
        name nullable: true
        text maxSize: 512
        text nullable: true, blank: true
        template maxSize: 512, nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }

    String toString()
    {
        name
    }
}
